package com.cat.binaryTree;

/**
 *   @description https://leetcode.cn/problems/paths-with-sum-lcci/description/
 *   @author 曲大人的喵
 *   @create 2025/9/14 19:46
 *   @since JDK17
 */

public class Solution40 {
    int f(TreeNode root, int sum) {
        if (root == null) {
            return 0;
        }
        sum -= root.val;
        return f(root.left, sum) + f(root.right, sum) + (sum == 0 ? 1 : 0);
    }
    public int pathSum(TreeNode root, int sum) {
        if (root == null) {
            return 0;
        }
        return pathSum(root.left, sum) + pathSum(root.right, sum) + f(root, sum);
    }
}
